/*******************************************************************************

This code file produces Figure A26, "Ranking Neighborhoods by 421-a's Marginal Value of Public Funds."

Run the MVPF programs before producing this figure.

*******************************************************************************/

*** Manage settings

	run "$dir/code/modules/settings.do"
	
* Load Stata-TeX

	do "$code/modules/stata-tex.do"
	cd "$tables/estimates"
	
*** Load data
	
	use "$data/clean/mvpf_by_nta_boot.dta", clear

	collapse (mean) mvpf_mean=mvpf (semean) mvpf_se=mvpf, by(nta_code)
	
	csranks, id(nta_code) mean(mvpf_mean) se(mvpf_se) simultaneous b(1000) 
	
	local N = _N
	
	foreach v of varlist nta_code_rk* {
		replace `v' = 1 - `v' / `N'
	}
	
	merge 1:1 nta_code using "$data/GIS_boundaries/neighborhood_boundaries/df.dta", nogen
		
	colorpalette9 Blues, nograph n(4)
	
	spmap nta_code_rk_min using "$data/GIS_boundaries/neighborhood_boundaries/coords.dta", ///
	 id(_ID) fcolor(`r(p)') osize(vthin vthin vthin vthin vthin vthin) ndsize(vthin) ///
	 legend(order(5 "(0.75, 1]" 4 "(0.5, 0.75]" 3 "(0.25, 0.5]" 2 "[0, 0.25]" 1 "No Data") position(4)) ///
	 clm(custom) clb(0 0.25 .50 .75 1) ndf(gs11)
	
	graph export "$figs/mvpf_ranks_min.pdf", replace
	graph export "$figs_overleaf/mvpf_ranks_min.pdf", replace
	
	colorpalette9 Blues, nograph n(4)
	
	spmap nta_code_rk_max using "$data/GIS_boundaries/neighborhood_boundaries/coords.dta", ///
	 id(_ID) fcolor(`r(p)') osize(vthin vthin vthin vthin vthin vthin) ndsize(vthin) ///
	 legend(order(5 "(0.75, 1]" 4 "(0.5, 0.75]" 3 "(0.25, 0.5]" 2 "[0, 0.25]" 1 "No Data") position(4)) ///
	 clm(custom) clb(0 0.25 .50 .75 1) ndf(gs11)
	
	graph export "$figs/mvpf_ranks_max.pdf", replace
	graph export "$figs_overleaf/mvpf_ranks_max.pdf", replace
